package com.changxianggu.cloud;

import cn.hutool.core.date.DateUtil;
import com.changxianggu.cloud.edu.tool.constant.CommonConstant;
import com.changxianggu.cloud.edu.tool.constant.HttpConstant;
import com.changxianggu.cloud.edu.tool.utils.ConfigUtil;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Date;

/**
 * 启动主程序
 *
 * @author liuyuantao
 */
@Slf4j
public class ApplicationMain extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
        //检测数据库文件
        ConfigUtil.copyResourcesFile(ConfigUtil.CONFIG_FILE);
        //检测创建快捷方式的文件
        URL url = Thread.currentThread().getContextClassLoader().getResource("fxml/Main.fxml");
        Parent root = FXMLLoader.load(url);
        primaryStage.setTitle(CommonConstant.MAIN_TITLE);
        primaryStage.setScene(new Scene(root, 500, 160));
        primaryStage.setResizable(false);
        primaryStage.getIcons().add(new Image("image/icon.png"));
        primaryStage.show();
        log.debug("应用程序启动,当前时间:{}", DateUtil.format(new Date(), "yyyy-MM-dd hh:mm:ss"));
        primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
            @Override
            public void handle(WindowEvent event) {
                log.debug("应用程序关闭,当前时间:{}", DateUtil.format(new Date(), "yyyy-MM-dd hh:mm:ss"));

            }
        });
    }

    public static void main(String[] args) {
        launch(args);
    }


}
